<div id="information">
<?php
$id = (int)$_GET['id'];

/* защита по ид */

if(!isset($id) || !is_numeric($id) || $id<1){
	echo "<h2>Немога да намеря страницата..</h2>";
}else {
?>
	<br /><br />
		<form action='' method='post' class="form">
				<h3 class="form_h3">Заглавие</h3> 
				<input type='text' name='title' value='<?php echo $_POST['title']; ?>'/>
				<h3 class="form_h3">Съдържание</h3> 
				<textarea cols='40' rows='5' name='descr'><?php echo $_POST['descr']; ?></textarea>
				<br /><br />
				<input type='submit' name='submit' value='Запази' />
		</form>
	<?php
	$sel_username_f = mysql_query('SELECT * FROM users WHERE username = "'.$_SESSION['username'].'"');
	$row_u_f = mysql_fetch_assoc($sel_username_f);
	
	$sel = "SELECT * FROM categories WHERE id='".$_GET['id']."'";
	$sel_q = mysql_query($sel);
	$row_c_title = mysql_fetch_assoc($sel_q);
	
		$title = htmlspecialchars(trim($_POST['title']));
		$descr = htmlspecialchars(trim($_POST['descr']));
		$type = $row_u_f['type'];
		$date = time();
		$username = $_SESSION['username'];
		$c_title = $row_c_title['cat_title'];
		
		if($_POST['submit']){
		if(!empty($title) && !empty($descr)){
			if(strlen($title) < 3 || strlen($descr) < 3) {
			   echo '<p class="error">Кратко име и/или описание!</p>';
			} else {
				$ins_cat = 'INSERT INTO cat_t(who_added, user_type, t_title, t_descr, date, c_title) 
						VALUES("'.$username.'", "'.$type.'", "'.$title.'", "'.$descr.'", "'.$date.'", "'.$c_title.'")';
				$ins_car_qe = mysql_query($ins_cat);
	            echo '<p class="success">Успешен запис!</p>';
				?>
				<meta http-equiv="refresh" content="0;url=<?php echo 'see_cat.php?id='.$_GET['id'].''; ?>">
				<?php
			}
		} else {
		   echo '<p class="error">Всички полета са задължителни!</p>';
		}
		}
	?>
	<br />
<?php
}
?>
</div>